//
//  TenderJPChooseCell.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2022/3/22.
//  Copyright © 2022 zwb. All rights reserved.
//

import UIKit

import Kingfisher
class ZyaTenderJPChooseCell: ZyaTenderBaseCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
         
    }
    /// 三种模式   出价样式  销售出价带图标样式    销售出价不带图样式  --- withPicture 只有销售出价用到
    
    func makeConstrainsts(_ listType:TBandJPType = .TB,withPicture:Bool = true) {
   
        oper_btn.layer.cornerRadius = 3
        oper_btn.layer.borderColor = #colorLiteral(red: 0.1411764771, green: 0.3960784376, blue: 0.5647059083, alpha: 1)
        oper_btn.layer.borderWidth = 1
        oper_btn.setTitleColor(#colorLiteral(red: 0.1411764771, green: 0.3960784376, blue: 0.5647059083, alpha: 1), for: .normal)

        
            dingwei.isHidden = true
           
                imageV.snp.makeConstraints { (make) in
                    make.left.equalTo(self.contentView).offset(12)
                    make.centerY.equalTo(self.contentView)
                    make.width.height.equalTo(95)
                }
                lab1.snp.makeConstraints { (make) in
                    make.left.equalTo(imageV.snp.right).offset(12)
                    make.right.equalTo(self.contentView).offset(-10)
                    make.top.equalTo(self.contentView).offset(12)
                    //                make.bottom.equalTo(self).offset(-100)
                }
                btn1.snp.makeConstraints { (make) in
                    make.left.equalTo(lab1)
                    make.width.equalTo(60)
                    make.height.equalTo(25)
                    make.top.equalTo(lab1.snp.bottom).offset(3)
                }
                chujiaLab.snp.makeConstraints { (make) in
                    make.centerY.equalTo(btn1)
                    make.right.equalTo(self.contentView).offset(-10)
                }
                
                lab2.snp.makeConstraints { (make) in
                    make.left.right.equalTo(lab1)
                    make.top.equalTo(btn1.snp.bottom).offset(3)
                }
                lab3.snp.makeConstraints { (make) in
                    make.left.right.equalTo(lab1)
                    make.top.equalTo(lab2.snp.bottom).offset(3)
                }
                
                lab4.snp.makeConstraints { (make) in
                    make.left.right.equalTo(lab1)
                    make.top.equalTo(lab3.snp.bottom).offset(3)
                    
                }
                oper_btn.snp.makeConstraints { (make) in
                    make.top.equalTo(lab4.snp.bottom).offset(2)
                    make.width.equalTo(70)
                    make.right.equalTo(self.contentView).offset(-15)
                    make.height.equalTo(30)
                    make.bottom.equalTo(self.contentView).offset(-5)
                }
         
            
       
        
        
        
    }
    
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var one = ZyaZtbContentModel(JSON:["":""])! {
        didSet {
             if one.innerType! == .jpListKHW || one.innerType! == .jpMyjpKHW || one.innerType! == .jpMyMarkKHW || one.innerType! == .jpInfo_oaOA || one.innerType! == .jpInfo_followTagOA {
                
                lab1.text = one.zTitle
           
                 
                 let real_status = one.zStatus.isSome ? intTran(one.zStatus) : intTran(one.zZbStatus)
                 var btnName =  ""
                  if real_status == 1 {
                     btnName =  "已成交"
                  } else if real_status == 0 {
                     btnName =  "未成交"
                  } else {
                     btnName =  "已放弃"
                  }
                 btn1.setTitle(btnName, for: .normal)
                 
                 
                 
                 
                let ssst = btnName == "未开始" ? "\(one.zBeginDate.unwrap)开始" : "\(one.zEndDate.unwrap)结束"
                lab2.text =  "\(ssst)   \(one.zCity.unwrap)"
                lab3.text = "出栏时间:\(one.zDate.unwrap)至\(one.zDateEnd.unwrap)"
                lab4.text = one.zPriceRank.unwrap
                chujiaLab.text = "\(intTran(one.zBidCount))次出价"
                
                if  let imageUrl = URL(string:configKSURL(one)) {
                    let resource = KF.ImageResource(downloadURL: imageUrl)
                    imageV.kf.setImage(with: resource, placeholder: UIImage(named:"defaultImg"))
                }
                 
                    oper_btn.setTitle("选择", for: .normal)
                    oper_btn.addTarget(self, action: #selector(btn2Action(sender:)), for: .touchUpInside)
                 
                

                if oper_btn.titleLabel!.text.unwrap.isEmpty {
                    oper_btn.snp.remakeConstraints { (make) in
                        make.top.equalTo(lab4.snp.bottom).offset(2)
                        make.width.equalTo(1)
                        make.right.equalTo(self.contentView).offset(-15)
                        make.height.equalTo(1)
                        make.bottom.equalTo(self.contentView).offset(-5)
                    }
                }
                
            }
            
            
        }
    }
    @objc func btn2Action(sender:UIButton) {
        if let closure = btn2Closure {
            closure(sender,sender.titleLabel!.text.unwrap)
        }
    }
    
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
